package multiThread;

// Multi thread Example with Bike Game
// join() - the parents waits till the child completes.

class Ax implements Runnable {
	public void run() {
		for (int i = 0; i < 30; i++) {
			System.out.println(Thread.currentThread().getName() + " Leading.");
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
			}
		}
	}
}

class Bx implements Runnable {
	public void run() {
		Thread t = Thread.currentThread();
		String name = t.getName();
		for (int i = 0; i < 20; i++) {
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
			}
			System.out.println(name + " Leading.");
		}
	}

}

public class MyThread5 {
	public static void main(String args[]) throws InterruptedException {
		Ax obj1 = new Ax();
		Bx obj2 = new Bx();

		// Creation of thread.
		Thread t1 = new Thread(obj1);
		Thread t2 = new Thread(obj2);

		t1.setName("Bike 1 ");
		t2.setName("Bike 2 ");

		System.out.println("1..");
		Thread.sleep(500);
		System.out.println("2..");
		Thread.sleep(500);
		System.out.println("3..");
		Thread.sleep(500);
		System.out.println("Game Started....");

		// Thread is made runnable.
		t1.start();
		t2.start();

		t1.join();
		t2.join();

		System.out.println("....Game Ended.");

	}
}